package com.shujia.day12;



import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class Demo02IOReadTxt {
    public static void main(String[] args) {

        // 需求：读取一个文本文件数据，并将读取到的字节转换成字符串
        String path = "data/data.txt";
        int capacityLen = 10;
        try {
            byte[] bytes = new byte[capacityLen];
            FileInputStream fileInputStream = new FileInputStream(path);
            int readLen = 0;
            while ((readLen = fileInputStream.read(bytes))>0){
                // 将数据转成字符串
                // 直接转换数据换行乱了？
                System.out.print(new String(bytes,0,readLen));
            }

        } catch (FileNotFoundException e) {
            System.err.println("文件找不到错误...");
        } catch (IOException e) {
            System.err.println("数据读取错误...");
        }
//        catch (IOException e) {
//            throw new RuntimeException(e);
//        }


    }
}
